var fs = require("fs");
var request = require("request");// 请求
var cheerio = require("cheerio");//cheerio 解析 HTML
var iconv = require('iconv-lite');//Node.js 抓取非 utf-8 的中文网页时会出现乱码问题

let url = "http://www.ibiquge.cc/ddddfdffd.php?ie=gbk&q=" + encodeURI('斗罗'); // 目标网站

function objFn() {
    console.log('测试')
    var _this = this;
    this.getContent = function () {
        request({
            url: url,
            method: "GET",
            // gzip:true,
            encoding: null//获取的内容不编码，二进制
        }, function (error, response, body) {
            // console.log(response);
            console.log('测试')
            if (!error) {
                var strJson = iconv.decode(body, "GBK"); //进行gbk解码
                console.log(strJson)
                var $ = cheerio.load(strJson, { decodeEntities: false }); //解决Unicode 编码

                console.log($("h1").html(), $("#content").html());
                _this.contentEach($("h1").html(), $("#content").html());
            } else {
                console.log(error)
            }
        })
    };
    this.contentEach = function (title, content) {
        fs.writeFile('./a.txt', content, function (err) {
            console.log(err)
        })
    }

}
var obj = new objFn();
obj.getContent('4954117.html');